"""
双端队列deque的使用示例
"""

import copy
from collections import deque

if __name__ == '__main__':
    # deque GIL是线程安全，而list不是线程安全的
    user_deque = deque()

    user_deque.append("Google")
    user_deque.appendleft("Apple")
    user_deque.appendleft(['Alibaba'])
    print(user_deque)
    # 输出结果：
    # deque([['Alibaba'], 'Apple', 'Google'])

    # 浅拷贝
    user_deque_copy = user_deque.copy()
    user_deque_copy.append("Amazon")
    user_deque_copy[0].append("Tesla")
    print(user_deque)
    print(user_deque_copy)
    # 输出结果：
    # deque([['Alibaba', 'Tesla'], 'Apple', 'Google'])
    # deque([['Alibaba', 'Tesla'], 'Apple', 'Google', 'Amazon'])

    # 深拷贝
    user_deque_deep_copy = copy.deepcopy(user_deque)
    user_deque_deep_copy[0].append("Netflix")
    print(user_deque)
    print(user_deque_deep_copy)
    # 输出结果：
    # deque([['Alibaba', 'Tesla'], 'Apple', 'Google'])
    # deque([['Alibaba', 'Tesla', 'Netflix'], 'Apple', 'Google'])

    # 扩容
    user_deque_extend = copy.deepcopy(user_deque)
    user_deque_extend.extend(user_deque)
    print(user_deque_extend)
    # 输出结果：
    # deque([['Alibaba', 'Tesla'], 'Apple', 'Google', ['Alibaba', 'Tesla'], 'Apple', 'Google'])
